﻿using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System.Threading;

namespace SharpAnalyzer.Utilities
{
    internal static class SyntaxExtensions
    {
        public static string GetName(this NamespaceDeclarationSyntax node, SyntaxNode rootNode)
        {
            NameSyntax name = node.Name;
            return rootNode.GetText().GetSubText(name.Span).ToString();
        }

        public static string GetName(this TypeDeclarationSyntax node, SyntaxNode rootNode)
        {
            SyntaxToken identifier = node.Identifier;
            return rootNode.GetText().GetSubText(identifier.Span).ToString();
        }

        public static int GetLineNumber(this SyntaxNode syntax)
        {
            Location location = syntax.GetLocation();
            return location.SourceTree.GetLineSpan(location.SourceSpan).StartLinePosition.Line;
        }
    }
}